<template>
  <el-form :model="roleForm" label-width="120px">
    <el-form-item label="角色名称">
      <el-input v-model="roleForm.name" />
    </el-form-item>

    <el-form-item label="角色描述">
      <el-input type="textarea" v-model="roleForm.description" />
    </el-form-item>

    <el-form-item label="状态">
      <el-switch
        :active-value="1"
        :inactive-value="0"
        v-model="roleForm.status"
      />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
      <el-button @click="handleClose">取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script lang="ts" setup>
import { reactive, ref, defineProps, defineEmits } from "vue";
import { roleAdd } from "@/api/role/index";
import { ElMessage } from "element-plus";
const emits = defineEmits(["handleCloseDailog"]);
// emits('handleCloseDailog')

// defineProps 接收的参数  ,父页面的属性  comData
// defineEmits   父页面的事件  handleCloseDailog（自定义事件）

/**
 * 表单数据
 */
const defaultForm = {
  name: "",
  description: "",
  status: 1,
};

/**
 * 响应式表单数据
 */
let roleForm = reactive(defaultForm);

const restForm = () => {
  roleForm = defaultForm;
  console.log(roleForm);
};

const handleClose = () => {
  emits("handleCloseDailog");
};

const onSubmit = async () => {
  let result: any = await roleAdd(roleForm);
  ElMessage({
    type: result.code == 200 ? "success" : "error",
    message: result.mess,
  });
  emits("handleCloseDailog");
};
</script>
